<?php

namespace app\admin\model\yunfood;

/**
 * 打印机
 */
class PrinterDevice extends \addons\yunfood\model\PrinterDevice
{
    // 自定义初始化
    protected static function init()
    {
        self::beforeWrite(function ($record) {
            $scenario = $record->data['scenario'] ?? null;
            if ($scenario) {
                $config = null;
                if ($record->brand == self::BRAND_FEIE) {
                    $config = $record->data['feieData'];
                } elseif ($record->brand == self::BRAND_YILIANYUN) {
                    $config = $record->data['yilianyunData'];
                } elseif ($record->brand == self::BRAND_ZHONGWU) {
                    $config = $record->data['zhongwuData'];
                }
                $record['config'] = $config ? json_encode($config) : null;

                $scenes = $record->data['scenes'];
                $record->scenes = implode(',', $scenes);
            }

            return true;
        });
    }
}
